﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HR.Appointments.Service.Tools
{
    /// <summary>
    /// Registry class to store data access layer objects
    /// </summary>
    public class Registry
    {
        private static Dictionary<Type, object> _classList = new Dictionary<Type, object>();

        /// <summary>
        /// Clear the list
        /// </summary>
        public static void Inizialize()
        {
            _classList.Clear();
        }

        /// <summary>
        /// Register a data access object class to the registry
        /// </summary>
        /// <param name="dao">The dataaccess layer class</param>
        /// <param name="domainClass">The interface type of the class</param>
        public static void RegisterDAO(object dao, Type domainClass)
        {
            _classList.Add(domainClass, dao);
        }

        /// <summary>
        /// Removes the data access layer the from the registry
        /// </summary>
        /// <param name="domainClass">The interface type of the class</param>
        public static void DeRegisterDAO(Type domainClass)
        {
            _classList.Remove(domainClass);
        }

        /// <summary>
        /// Get a specific data access layer type form the registry
        /// </summary>
        /// <param name="domainClass">The interface type of the class</param>
        /// <returns>The data access layer registyer to this interface</returns>
        public static object GetDAO(Type domainClass)
        {
            try
            {
                return _classList[domainClass];
            }
            catch
            {
                throw new ServiceException("Class type was not registered");
            }
        }
    }
}
